/*
Reading analoge signal and posting it to serial LCD

Physical Connections:
-------------------------
Arduino  | Peripherals
-------- | --------------
TX1 ------ SerLCD "RX"
5V ------- SerLCD "VCC"
GND ------ SerLCD "GND"

Pin A0 --- Analoge Input 0
Pin A1 --- Analoge Input 1
GND ------ Ground
*/


  int A0Raw;     //This will store our raw ADC data
  int A1Raw;
  float A0Final; //This will store the converted data
  float A1Final;

void setup() {
    
  Serial1.begin(9600);
  backlightSerLcd(70);
  clearSerLcd();
  Serial1.print("Muthanna 2012!!");
  delay(2000);
}


void loop() { 

  //Measurement
  A0Raw = analogRead(A0);
  A1Raw = analogRead(A1);
  A0Final = map(A0Raw,0,1023,0,5);
  A1Final = map(A1Raw,0,1023,0,5);
  
  clearSerLcd();
     
  Serial1.print("A0 = ");
  Serial1.print(A0Final);
  Serial1.print("V ");
  Serial1.print(A0Raw);
  
  line2SerLcd();
  Serial1.print("A1 = ");
  Serial1.print(A1Final);
  Serial1.print("V ");
  Serial1.print(A1Raw);
  delay(200);
}

/*----------------------------------------------------------------------------------------------*/
void clearSerLcd(){
  Serial1.write(0xFE);                              //command flag
  Serial1.write(0x01);                              //clear command.
  delay(50);
}
/*----------------------------------------------------------------------------------------------*/
void backlightSerLcd(int thePercentage){            //turns on the backlight
  Serial1.write(0x7C);                              //command flag for backlight stuff
  int theValue = map(thePercentage, 0,100,128,157); // maps percentage to what SerLCD wants to see
  Serial1.write(theValue);                          //light level.
  delay(50);
}
/*----------------------------------------------------------------------------------------------*/
void line2SerLcd(){
  Serial1.write(0xFE);                              //command flag
  Serial1.write(0xC0);                              //move cursor to first location in 2nd line.
  delay(50);
}
/*----------------------------------------------------------------------------------------------*/
